package com.yueqian.controller;

import com.yueqian.dao.IPermissionsDao;
import com.yueqian.domain.Permission;
import com.yueqian.service.IPermissionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("permission")
public class PermissionController {

    @Autowired
    private IPermissionsService permissionsService;

    @RequestMapping("findAll.do")
    public ModelAndView findAll() throws Exception {
        List<Permission> permissionList = permissionsService.findAll();
        ModelAndView mav = new ModelAndView();
        mav.addObject("permissionList", permissionList);
        mav.setViewName("permission-list");
        return mav;
    }

    @RequestMapping("save.do")
    public String save(Permission permission) throws Exception {
        permissionsService.save(permission);
        return "redirect:findAll.do";
    }
}
